package com.scott.crm.clazz.service.serviceImpl;

import com.scott.base.utils.GetDateTime;
import com.scott.crm.clazz.bean.ClazzBean;
import com.scott.crm.clazz.dao.ClazzDao;
import com.scott.crm.clazz.dto.ClazzDto;
import com.scott.crm.clazz.service.ClazzService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
/*
 * 方法描述:
 * @author: 李伟伟
 * @date: 2021/11/30 11:17
 */
@Service
public class ClazzServiceImpl implements ClazzService {

    @Autowired
    private ClazzDao dao;

    @Override
    public List<ClazzBean> findClazzList(Integer begin, Integer end) {
        List<ClazzBean> clazzList = dao.findClazzList(begin, end);
        return clazzList;
    }

    @Override
    public Integer addClazz(ClazzBean clazzBean) {
        String now = GetDateTime.nowTime();
        clazzBean.setCreateTime(now);
        clazzBean.setLastUpdateTime(now);
        return dao.addClazz(clazzBean);
    }

    @Override
    public Integer deleteClazz(ClazzDto clazzDto) {
        List<Integer> ids = clazzDto.getIds();

        Integer integer=0;
        for (int index=0;index<ids.size();index++){
            Integer classId = ids.get(index);
            Integer count = dao.count(classId);
            if (count!=0){
             continue;

            }else {
                integer= dao.deleteClazz(classId);
            }
        }
        return integer;
    }


//    @Override
//    public Integer deleteClazz(ClazzDto clazzDto) {
//        List<Integer> ids = clazzDto.getIds();
//        for(Integer id:ids){
//        ClazzBean bean=new ClazzBean();
//        bean.setId(id);
//        return  dao.deleteByPrimaryKey(id);
//
//        }




    @Override
    public Integer updateClazzByClazzId(ClazzBean clazzBean) {

        Integer classId = clazzBean.getId();

        Integer count = dao.count(classId);
        if (count!=0){
            return 0;

        }else {
            clazzBean.setLastUpdateTime(GetDateTime.nowTime());
            return dao.updateByPrimaryKeySelective(clazzBean);
        }


    }


    @Override
    public List<ClazzBean> selectAllClazz() {
        return dao.selectAllClazz();
    }

    @Override
    public List<ClazzBean> selectMessageById(Integer id) {
        return dao.selectMessageById(id);
    }



}
